/*
 Monkeyinvaders stuff
*/

#include "MonkeyInvaders.h"


MonkeyInvaders::MonkeyInvaders()
{

}



void MonkeyInvaders::chooseSceneManager()
{
	mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);

	// Show the frame stats overlay
	//mFrameListener->showDebugOverlay(true);

	ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

void MonkeyInvaders::createScene()
{
	//mSceneMgr->setWorldGeometry("terrain.cfg");

	ColourValue fadeColour(0.9, 0.9, 0.9);
	mWindow->getViewport(0)->setBackgroundColour(fadeColour);

	mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");

	// Set ambient light
	mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
	// LIGHTS!!
	// Create a point light
	Light* l = mSceneMgr->createLight("MainLight");

	// Accept default settings:SceneManager *sceneMgr, point light, white diffuse, just set position
	// NB I could attach the light to a SceneNode if I wanted it to movt really want ode to react on a collision, so calling collide() will return false. Now there is memory used for those adjustment variables we do not really need. If you think this is nonsense, feel free to implement it in one class.e automatically with
	//  other objects, but I don't
	l->setType(Light::LT_DIRECTIONAL);
	l->setDirection(-0.5, -0.5, 0);

	// CAMERA!!
	mCamera->setPosition (0, 0, 0);	// Required or else the camera will have an offset

    mWorld = new OgreOde::World(mSceneMgr);
    mWorld->setGravity(Vector3(0,0,0));
    mWorld->setCFM(10e-5);
    mWorld->setERP(0.8);
    mWorld->setAutoSleep(true);
    mWorld->setAutoSleepAverageSamplesCount(10);
    mWorld->setContactCorrectionVelocity(1.0);
    mWorld->setShowDebugGeometries(true);
    mWorld->setShowDebugContact(true);

	// ACTION!!!
	// Fill the scene with some razors
	
	info_manager = new InfoManager();

	// Main character
	OgreCharacter *ogre = new OgreCharacter ("player_0", mWorld);

    enemy_manager = new EnemyManager(mWorld);

	ogre->set_enemy_manager(enemy_manager);

	ExtendedCamera *exCamera = new ExtendedCamera ("Extended Camera", mSceneMgr, mCamera);

	// Frame listener to manage both character and camera updating and different camera modes
	// Need to create it here as we want to change some parameters here, thus avoiding defining 
	// ogre and exCamera as member variables
	mFrameListener = new MonkeyFrameListener (mWindow, mCamera, NULL);
	static_cast<MonkeyFrameListener *>(mFrameListener)->setCharacter (ogre);
	static_cast<MonkeyFrameListener *>(mFrameListener)->setExtendedCamera (exCamera);

    static_cast<MonkeyFrameListener *>(mFrameListener)->set_enemy_manager(enemy_manager);
	
	static_cast<MonkeyFrameListener *>(mFrameListener)->set_info_manager(info_manager);
	

}

void MonkeyInvaders::destroyScene()
{
}

void MonkeyInvaders::createFrameListener()
{
	// This is where we instantiate our own frame listener
	// mFrameListener= new MonkeyFrameListener(mWindow, mCamera);
	mRoot->addFrameListener(mFrameListener);
}
